package com.zhx.basis.juc;

import com.zhx.basis.设计模式.模板模式.demo1.main;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

public class CompletableFuture使用 {

    public static void main(String[] args) {

        List<String> list1=new ArrayList<>();
        list1.add("1");
        list1.add("1");
        list1.add("1");

        List<String> list2=new ArrayList<>();
        list2.add("2");
        list2.add("2");
        list2.add("2");

        List<String> list3=new ArrayList<>();
        list3.add("3");
        list3.add("3");
        list3.add("3");





        CompletableFuture<List<String>> task1 =
                CompletableFuture.supplyAsync(()->{
                    list1.add("11");
                    return list1;
                });
        CompletableFuture<List<String>> task2 =
                CompletableFuture.supplyAsync(()->{
                    list2.add("22");
                    return list2;
                });
        CompletableFuture<List<String>> task3 =
                CompletableFuture.supplyAsync(()->{
                    list3.add("22");
                    return list3;
                });
        CompletableFuture<Void> headerFuture=CompletableFuture.allOf(task1,task2,task3);


        try {
            headerFuture.join();
        } catch (Exception ex) {
        }
        System.out.println("all done. ");
        System.out.println();
    }
}
